import { getBandId } from '@/base/constant';
import CoreRequest from '@/base/newCoreAxios';
import RequestOption from '@/base/RequestOption';
const cr = new CoreRequest();

export default class BandDao {
  /**
   * 根据帮区ID获取帮区
   * @param bandID 帮区ID
   * @returns
   */
  async getBandByID(bandID: number) {
    const ro = new RequestOption();
    ro.singleResult = true;
    return await cr.get(
      '/core/v4/band/' + bandID,
      {
        filed: ['departmentID', 'objID', 'organizationID'],
        extend: {
          department: ['departmentName'],
          organization: ['organizationName'],
          creator: ['userName'],
          permission: []
        },
        gid: bandID
      },
      ro
    );
  }

  /**
   * 根据帮区ID获取子帮区
   * @param bandID 帮区ID
   * @returns
   */
  async getSubBands(pagination: any, bandID: number) {
    const ro = new RequestOption();
    ro.pagination = pagination;
    return await cr.get(
      '/core/v4/band/' + bandID + '/band',
      {
        gid: bandID
        // 扩展参数，获取部门、机构和创建者名字
        // 'filed': ['departmentID','objID','organizationID'],
        // 'extend':{'department':['departmentName'],'organization':['organizationName'],'creator':['userName'],'permission':[]},
      },
      ro
    );
  }

  /**
   * 根据帮区ID获取帮区工具
   * @param bandID 帮区ID
   * @returns
   */
  async getBandTools() {
    const ro = new RequestOption();
    const bandID = getBandId();
    return await cr.get(
      '/core/v4/band/' + bandID + '/tool',
      {
        gid: bandID,
        // extend:JSON.stringify({ "creator": ["userName"], }),
      },
      ro
    );
  }

  /**
   * 根据帮区ID获取帮区消息板
   * @param bandID 帮区ID
   * @returns
   */
  async getBandChatrooms() {
    const ro = new RequestOption();
    const bandID = getBandId();
    return await cr.get(
      '/core/v4/band/' + bandID + '/chatroom',
      {
        gid: bandID,
      },
      ro
    );
  }

}
